package com.dzl.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;

import java.util.concurrent.Executor;


/**
 * 描述:通过异步线程执行耗时任务比如批量导入用户
 * @author: liuguanjun
 * @date: 2021/09/10
 * @version: V1.0
 */
@Configuration
@ComponentScan("com.dzl.**.impl")
@EnableAsync
public class ThreadConfig {
    /**
     * 执行需要依赖线程池，这里就来配置一个线程池
     * @return
     */
    @Bean
    public Executor getExecutor() {
        ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
        executor.setCorePoolSize(10);
        executor.setMaxPoolSize(100);
        executor.setQueueCapacity(250);
        executor.initialize();
        return executor;
    }
}